package com.deeper.customview.ui.c1.demo;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.deeper.customview.BaseFragment;
import com.deeper.customview.R;

public class Chapter01Demo01Fragment extends BaseFragment {
    private ImageView iv;


    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View root = inflater.inflate(R.layout.fragment_chapter01_demo01, container, false);

        iv = root.findViewById(R.id.iv);

        Bitmap bmp = Bitmap.createBitmap(400, 400, Bitmap.Config.ARGB_8888);

        Canvas canvas = new Canvas(bmp);
        //绘制文字
        Paint paint = new Paint();
        paint.setAntiAlias(true);
        paint.setStyle(Paint.Style.FILL);
        paint.setTextAlign(Paint.Align.LEFT);
        int sp = 18;
        paint.setTextSize(sp);
        paint.setTextSkewX(0.5f);
        paint.setUnderlineText(true);
        paint.setFakeBoldText(true);

        canvas.drawColor(Color.RED);
        canvas.drawText("好好学习，天天向上", 10, 30, paint);


        paint.setStyle(Paint.Style.STROKE);
        paint.setColor(Color.GREEN);
        paint.setStrokeWidth(20);
        paint.setStrokeJoin(Paint.Join.ROUND);

        canvas.drawRect(new Rect(20, 200, 350, 350), paint);

        iv.setImageBitmap(bmp);

        return root;
    }
}
